package com.loan.util;
import java.util.Random;

public class RandomCodeUtil {

	
	public static String getCode(){
        int x;//定义两变量
        Random ne=new Random();//实例化一个random的对象ne
        x=ne.nextInt(9999-1000+1)+1000;//为变量赋随机值1000-9999
        return String.valueOf(x);
	}
	
    public static String getEmailCode(){  
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 6; i++) {
            int a = Math.abs((new Random()).nextInt(57));// 产生0~57的随机数
            if (a <= 9) {// 将0~9转为char的0~9
                sb.append((char) (a + 48));
            } else if (a < 33) {// 将10~33转为char的A~Z
                if((a + 55) == 79 || (a + 55) == 73){
                    sb.append((char) (a + 63));
                }else{
                    sb.append((char) (a + 55));
                }
            } else {// 将33~57转为char的a~z
                sb.append((char) (a + 63));
            }
        }
        return sb.toString();
    }
}
